package com.ciwong.epaper.modules.login;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.bean.BrandBean;

import java.util.List;


public class BrandAccountAdapter extends BaseAdapter {

    /**
     * 已登录过账号集合
     */
    private List<BrandBean> mBrandBeanList;
    private Context         mContext;

    public void setPopListItemListener(PopListItemListener popListItemListener) {
        mPopListItemListener = popListItemListener;
    }

    private PopListItemListener mPopListItemListener;



    public BrandAccountAdapter(Context context, List<BrandBean> brandBeanList)
    {
        this.mBrandBeanList = brandBeanList;
        this.mContext=context;
    }

    @Override
    public int getCount()
    {
        return mBrandBeanList == null ? 0 : mBrandBeanList.size();
    }

    @Override
    public Object getItem(int position)
    {
        return mBrandBeanList == null || mBrandBeanList.isEmpty()
                ? null : mBrandBeanList.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(final int position, View convertView,
                        ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.adapter_brand_account,parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TextView brandName = (TextView) viewHolder.mView.findViewById(R.id.brand_name);
        ImageView brandIv = (ImageView) viewHolder.mView.findViewById(R.id.iv_brand);
        brandName.setText(mBrandBeanList.get(position).getBrandName());
        brandIv.setImageResource(mBrandBeanList.get(position).getResId());
        return convertView;
    }

    public void clear() {
        mBrandBeanList.clear();
    }

    public void addAll(List<BrandBean> brandBeanList) {
        mBrandBeanList.addAll(brandBeanList);
        notifyDataSetChanged();
    }

    public class ViewHolder {
        View mView;
        public ViewHolder(View view) {
            mView = view;
        }
    }



}
